SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.vw_ListarCupos
AS
SELECT     c.idcupo, c.CicloLectivo, c.Organizacion, c.Carrera, c.Curso, c.CantidadDeCupos, o.Nombre, o.CUISE, COUNT(i.idInscripcion) AS cantInscripciones
FROM         dbo.tb_cupos c INNER JOIN
                      dbo.tb_Inscripciones i ON i.Organizacion = c.Organizacion AND i.AnioLectivo = c.CicloLectivo INNER JOIN
                      dbo.tb_Organizaciones o ON o.idOrganizaciones = c.Organizacion
GROUP BY c.idcupo, c.CicloLectivo, c.Organizacion, c.Carrera, c.Curso, c.CantidadDeCupos, o.Nombre, o.CUISE
GO
GRANT SELECT ON  [dbo].[vw_ListarCupos] TO [Alumnos]
GRANT SELECT ON  [dbo].[vw_ListarCupos] TO [Coordinaciones]
GRANT SELECT ON  [dbo].[vw_ListarCupos] TO [SoloVer]
GO
